package com.aaa.web.service.batterymangerservice.batterymangerserviceimpl;

import com.aaa.entity.BatteryPosition;
import com.aaa.web.commons.BatteryInfoQuery;
import com.aaa.web.commons.Result;
import com.aaa.web.dao.baterymangerdao.BatteryMangerDao;
import com.aaa.web.service.batterymangerservice.BatteryMangerBiz;
import com.aaa.web.systemconst.ISystemConst;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * com.aaa.web.service.batterymangerservice.batterymangerserviceimpl class
 *
 * @author Kevin Jia
 * @CLASS:BatteryMangerBizImpl
 * @Date:2018/12/19 16:31
 */

@Service
public class BatteryMangerBizImpl implements BatteryMangerBiz {

    @Autowired
    private BatteryMangerDao batteryMangerDao;


    /**
     * @Description: 获取当前门店管理的站点
     * @Param: lng,lat
     * @return: List<BatteryPosition>
     * @Author: Kevin Jia
     * @Date: 2018/12/25
     * @Time: 19:52
     */
    @Override
    public List<BatteryPosition> getPosition(String lng, String lat) {
        
        return batteryMangerDao.getPosition(lng, lat);
    }

    /**
     * @Description: 
     * @Param: query,batteryPosition
     * @return: Map
     * @Author: Kevin Jia
     * @Date: 2018/12/26
     * @Time: 10:03
     */
    @Override
    public Map getBatteryInfo(BatteryInfoQuery query,BatteryPosition batteryPosition) {
        int page = query.getPage();
        int size = query.getLimit();
        PageHelper.startPage(page, size);
        Map map = new HashMap();

        map.put("data", batteryMangerDao.getBatteryInfo(batteryPosition));
        map.put("count", batteryMangerDao.getBateryAddCount());
        map.put("code", ISystemConst.SU_COD);
        map.put("msg", "");
        return map;
    }

    /**
     * @Description:
     * @Param: String
     * @return:
     * @Author: Kevin Jia
     * @Date: 2018/12/21
     * @Time: 18:55
     */
    @Override
    public Map getSchools(String school, BatteryInfoQuery query) {
        int page = query.getPage();
        int size = query.getLimit();
        PageHelper.startPage(page, size);
        Map map = new HashMap();
        String msg = null;
        if(school == null ||"".equals(school)){

        }else {
            List list = new ArrayList();
            for (int i = ISystemConst.SU_COD; i <10 ; i++) {
                list.add(""+i+"");
            }
            List<BatteryPosition> schools ;
            Object schoolsCount ;
            if (list.contains(school)) {
                schools = batteryMangerDao.getSchoolsNm(school);
                schoolsCount = batteryMangerDao.getSchoolsNmCount();
            } else {
                schools = batteryMangerDao.getSchoolsCH(school);
                schoolsCount = batteryMangerDao.getSchoolsCHCount();
            }
            map.put("data", schools);
            map.put("count",schoolsCount );
        }
        map.put("code", ISystemConst.SU_COD);
        map.put("msg", msg);
        return map;
    }

    /**
     * @Description: 添加电瓶点
     * @Param: BatteryPosition
     * @return: Result
     * @Author: Kevin Jia
     * @Date: 2018/12/21
     * @Time: 20:53
     */
    @Override
    public Result InsertBatteryPosition(@RequestBody  BatteryPosition batteryPosition) {
        Result result = new Result();
        batteryMangerDao.InsertBatteryPosition(batteryPosition);
        result.setCode(ISystemConst.SU_COD);
        result.setMsg("插入成功");
        return result;
    }

    /**
     * @Description: 修改
     * @Param: BatteryPosition
     * @return: Result
     * @Author: Kevin Jia
     * @Date: 2018/12/22
     * @Time: 9:37
     */
    @Override
    public Result updateBatteryInfo(BatteryPosition batteryPosition) {
        Result result = new Result();
        batteryMangerDao.updateBatteryInfo(batteryPosition);
        result.setCode(ISystemConst.SU_COD);
        result.setMsg("修改成功");
        return result;
    }

    /**
     * @Description: 删除
     * @Param: id
     * @return: Result
     * @Author: Kevin Jia
     * @Date: 2018/12/24
     * @Time: 15:28
     */
    @Override
    public Result delBatteryInfo(String id) {
        Result result = new Result();
        batteryMangerDao.delBatteryInfo(id);
        result.setCode(ISystemConst.SU_COD);
        result.setMsg("删除成功");
        return result;
    }
}
